package com.panshi.bean;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

@Data
public class PageBean<T> implements Serializable {

    //当前页
    @ApiModelProperty("当前页")
    private Integer currentPage;

    //当前页的总条数
    @ApiModelProperty("当前页的总条数")
    private Integer currentPageSize;

    //总条数
    @ApiModelProperty("总条数")
    private Long countPage;

    //是否有下一页
    @ApiModelProperty("是否有下一页")
    private Integer isNext;

    //总页数
    @ApiModelProperty("总页数")
    private Integer totalPages;

    //开始索引
    @ApiModelProperty("开始索引")
    private Integer startIndex;

    //分页结果
    @ApiModelProperty("分页结果")
    private List<T> itemsList;

    public PageBean(){
        super();
    }

    public PageBean(Integer currentPage, Integer currentPageSize, Long countPage){
        this.currentPage = currentPage;
        this.currentPageSize = currentPageSize;
        this.countPage = countPage;
        this.totalPages = (Integer.parseInt(this.countPage.toString())+this.currentPageSize-1)/this.currentPageSize;
        this.startIndex = (this.currentPage-1)*this.currentPageSize;
        this.isNext = this.currentPage >= this.totalPages ? 0:1;

    }

}
